package com.piggy.logi.sys.controller;

import java.util.List;
import java.util.Arrays;

import com.piggy.common.log.annotation.LogiLog;
import com.piggy.logi.sys.bo.LogiScheduleExtEditBo;
import lombok.RequiredArgsConstructor;

import javax.validation.constraints.*;

import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import org.springframework.validation.annotation.Validated;
import com.piggy.common.log.annotation.Log;
import com.piggy.common.core.web.controller.BaseController;
import com.piggy.common.log.enums.BusinessType;
import com.piggy.logi.sys.vo.LogiScheduleExtVo;
import com.piggy.logi.sys.bo.LogiScheduleQueryBo;
import com.piggy.logi.sys.bo.LogiScheduleEditBo;
import com.piggy.logi.sys.service.ILogiScheduleService;
import com.piggy.common.core.utils.poi.ExcelUtil;
import com.piggy.common.core.web.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.piggy.common.core.domain.R;

import java.lang.Integer;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

/**
 * 调度车次信息Controller
 *
 * @author piggy
 * @date 2023-09-06
 */
@Api(value = "调度车次信息控制器", tags = {"调度车次信息管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/sys/schedule")
public class LogiScheduleController extends BaseController {

    private final ILogiScheduleService iLogiScheduleService;

    /**
     * 查询调度车次信息列表
     */
    @ApiOperation("查询调度车次信息列表")
    //@SaCheckPermission("sys:schedule:list")
    @PostMapping("/list")
    public TableDataInfo<LogiScheduleExtVo> list(@Validated @RequestBody LogiScheduleQueryBo bo) {
        return iLogiScheduleService.queryPageList(bo);
    }

    /**
     * 查询调度车次信息列表
     */
    @ApiOperation("查询调度车次信息列表,不分页")
    //@SaCheckPermission("sys:schedule:list")
    @PostMapping("/listNotPage")
    public List<LogiScheduleExtVo> listNotPage(@Validated @RequestBody LogiScheduleQueryBo bo) {
        return iLogiScheduleService.queryList(bo);
    }

    /**
     * 导出调度车次信息列表
     */
    @ApiOperation("导出调度车次信息列表")
    //@SaCheckPermission("sys:schedule:export")
    @LogiLog(title = "调度车次信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public void export(@Validated LogiScheduleQueryBo bo, HttpServletResponse response) throws IOException {
        List<LogiScheduleExtVo> list = iLogiScheduleService.queryList(bo);
        ExcelUtil<LogiScheduleExtVo> util = new ExcelUtil<LogiScheduleExtVo>(LogiScheduleExtVo.class);
        util.exportExcel(response, list, "调度车次信息");
    }

    /**
     * 获取调度车次信息详细信息
     */
    @ApiOperation("获取调度车次信息详细信息")
    //@SaCheckPermission("sys:schedule:query")
    @GetMapping("/{scheduleId}")
    public R<LogiScheduleExtVo> getInfo(@NotNull(message = "主键不能为空")
                                        @PathVariable("scheduleId") Long scheduleId) {
        return R.ok(iLogiScheduleService.queryById(scheduleId));
    }

    /**
     * 新增调度车次信息
     */
    @ApiOperation("新增调度车次信息")
    //@SaCheckPermission("sys:schedule:add")
    @LogiLog(title = "调度车次信息", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<LogiScheduleExtVo> save(@Validated @RequestBody LogiScheduleExtEditBo bo) {
        return R.ok(iLogiScheduleService.save(bo));
    }

    /**
     * 修改调度车次信息
     */
    @ApiOperation("修改调度车次信息")
    //@SaCheckPermission("sys:schedule:edit")
    @LogiLog(title = "调度车次信息", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<LogiScheduleExtVo> edit(@Validated @RequestBody LogiScheduleExtEditBo bo) {
        return R.ok(iLogiScheduleService.updateByEditBo(bo));
    }

}
